<?php
  require(dirname(__FILE__) . '/includes/init.php');
  $id_list = $db->getAll("select active_name,msg,count(send_id) as total_num,sum(money) as total_money from ".$ecs->table('send_detail')." group by active_id");
  if($_REQUEST['act'] == 'download'){
      $filename = date('Y-m-d-His',time()).'download';
	  header("Content-type: application/vnd.ms-excel; charset=utf-8");
      header("Content-Disposition: attachment; filename=$filename.xls");
	  $data  = "用户名" . "\t手机\t\n";
	  $send_num = intval($_REQUEST['send_num']);
	  $user_list = $db->getAll("select user_name,mobile from ".$ecs->table('send_user')." where send_num>$send_num");
	  if(count($user_list)>0){
	  	  foreach($user_list as $user){
		  	  $data .= $user['user_name']. "\t".$user['mobile']."\t\n";
		  }
	  }
	  $data = iconv('utf-8', 'gbk',$data);
	  echo $data. "\t";
	  exit;
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>管理中心 -发送记录 </title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="styles/general.css" rel="stylesheet" type="text/css" />
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
 
<h1>
<span class="action-span1"><a target="_top" href="index.php?act=main">管理中心</a> </span><span id="search_id" class="action-span1"> - 发送记录 </span>
<div style="clear:both"></div>
</h1>

  <div class="list-div" id="listDiv">
 
<table cellpadding="3" cellspacing="1">
  <tr>
    <th>时间</th>
    <th>活动标题</th>
    <th>数量</th>
    <th>短信内容</th>
	<th>短信订单</th>
    <th>订单金额</th>
    <th>净利</th>
  <tr>
  <?php 
  if(count($send_list)>0){
	foreach($send_list as $array_val){
  ?>
   <tr>
    <td><?php echo date('Y-m-d H:i:s',$array_val['send_time']);?></td>
    <td><?php echo $array_val['active_name'];?></td>
	<td><?php echo $array_val['total_num'];?></td>
	<td><?php echo $array_val['msg']?></td>
    <td><?php echo $array_val['total_money'];?></td>
    <td><?php echo $array_val['total_money']*$array_val['profit'];?></td>
  <tr>
  <?php 
      } 
	}
  ?>
  </table>
 
<!-- 分页 -->
  </div>
  
  <div class="form-div">
  	  <form action="send_list.php?act=download" method="post" onsubmit="return check_num()">导出发送次数大于<input name="send_num" size="2" type="text" id="send_num"/>的用户&nbsp;&nbsp;<input type="submit" name="readexcel" value="导出" class="button"/></form>
  </div>
  <script type="text/javascript">
  function check_num(){
  	  var send_num = $("#send_num").val();
	  var re = /^\+?[1-9][0-9]*$/;
	  if(!re.test(send_num)){
	      alert("请输入整数！");
		  return false;
	  }else{
	  	  return true;
	  }
  }
  </script>
</body>
</html>